package com.microstation.controller.system;

import com.microstation.common.Result;
import com.microstation.enums.ResultEnum;
import com.microstation.util.StringUtil;

public class BaseController {

    public static Result makeReturn(Boolean hasError, String errType, String error, String errUrl) {
        return new Result(hasError, errType, error, errUrl);
    }

    public static Result makeSuccess(String successInfo, String errUrl) {
        if (StringUtil.isNotEmpty(successInfo)) {
            return new Result(Boolean.FALSE, ResultEnum.SUCCESS.getType(), successInfo, errUrl);
        }
        return new Result(Boolean.FALSE, ResultEnum.SUCCESS.getType(), ResultEnum.SUCCESS.getInfo(), errUrl);
    }

    public static Result makeSuccess(Object object) {
        return new Result(Boolean.FALSE, ResultEnum.SUCCESS.getType(), object);
    }

    public static Result makeFail(String errType, String error, String errUrl) {
        return new Result(Boolean.TRUE, errType, error, errUrl);
    }

    public static Result makeFail(ResultEnum returnInfoEnum, String errUrl) {
        return new Result(Boolean.TRUE, returnInfoEnum.getType(), returnInfoEnum.getInfo(), errUrl);
    }

    public static Result makeError(String error, String errUrl) {
        return new Result(Boolean.TRUE, ResultEnum.ERROR.getType(), error, errUrl);
    }

    public static Result makeEmpty(String error, String errUrl) {
        return new Result(Boolean.TRUE, ResultEnum.EMPTY.getType(), error, errUrl);
    }
}
